package Threadprojects.pro2_knn.util;

import Threadprojects.pro2_knn.bean.BankMarketing;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

public class BankMarketingLoader {
    public static List<BankMarketing> load(String path){
        //数据列表
        ArrayList<BankMarketing> list = new ArrayList<>();
        //nio中的方法安全获取路径
        Path p= Paths.get(path);
        try {
            //高速缓冲流,又快又安全
            BufferedReader reader=new BufferedReader(new InputStreamReader(Files.newInputStream(p)));
            String s=null;
            while ((s=reader.readLine())!=null){
                // 分割数据放入一边
                String[] data = s.split(";");
                BankMarketing bank = new BankMarketing();
                bank.setData(data);
                list.add(bank);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return list;
    }
}
